package com.cetcs.kmga.dataManager.util;

import com.ccsc.auth.entity.ShiroSysUser;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

/**
 * 操作shiro的公共类
 *
 * @author xutao
 * @version V1.0 创建时间：2017-11-30 13:34
 *          Copyright 2017 by CETC
 */
public class ShiroOper {


    /**
     * 获取系统的用户
     *
     * @return
     */
    public static ShiroSysUser getShiroSysUser() {
        Subject currentUser = SecurityUtils.getSubject( );
        Session session = currentUser.getSession( );
        ShiroSysUser shiroSysUser = session != null ? (ShiroSysUser) session.getAttribute("loginSysUser") : null;
        return shiroSysUser;
    }

    /**
     * 获取当前用户的用户名 用户信息为空默认 zgwaAdminTest
     *
     * @return
     */
    public static String getUserName() {
        ShiroSysUser sysUser = getShiroSysUser( );
        String name = "zgwaAdminTest";
        if (sysUser != null) {
            name = sysUser.getAccount( );
        }
        return name;
    }

    /**
     * 获取当前用户的ID 用户信息为空默认 0
     *
     * @return
     */
    public static Integer getUserId() {
        ShiroSysUser sysUser = getShiroSysUser( );
        Integer id = 0;
        if (sysUser != null) {
            id = sysUser.getUserId( );
        }
        return id;
    }
}
